package com.ly.honor.controller;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ly.honor.entity.Game;
import com.ly.honor.entity.dto.GameCreatDTO;
import com.ly.honor.entity.dto.GameEditDTO;
import com.ly.honor.entity.dto.GameQueryDTO;
import com.ly.honor.entity.dto.NewsQueryDTO;
import com.ly.honor.entity.vo.GameQueryVO;
import com.ly.honor.entity.vo.NewsQueryVO;
import com.ly.honor.service.GameService;
import com.ly.honor.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.io.Serializable;
import java.util.List;

/**
 * (Game)表控制层
 *
 * @author makejava
 * @since 2022-11-16 11:53:56
 */
@RestController
@RequestMapping("game")
@Validated
@Api(tags = "游戏管理")
public class GameController {
    /**
     * 服务对象
     */
    @Resource
    private GameService gameService;

    /**
     *
     * @param pageNum
     * @param pageSize
     * @param gameQueryDTO
     * @return
     */
    @ApiOperation("条件分页查询")
    @PostMapping("getGamePageList/{pageNum}/{pageSize}")
    public Result getGamePageList(@PathVariable("pageNum") long pageNum,
                                  @PathVariable("pageSize") long pageSize,
                                  @RequestBody(required = false) GameQueryDTO gameQueryDTO, HttpServletRequest request) {
        Page<GameQueryVO> gameQueryVOPage =  gameService.getGamePageList(pageNum,pageSize,gameQueryDTO);
        return Result.ok(gameQueryVOPage);
    }

    @ApiOperation("查询所有信息")
    @GetMapping("getGameList")
    public Result getGameList() {
        List<Game> gameList = gameService.list();
        return Result.ok(gameList);
    }

    @ApiOperation("查询所有信息按热度降序")
    @GetMapping("getGameListDesc")
    public Result getGameListDesc() {
        List<Game> gameList =  gameService.getGameListDesc();
        return Result.ok(gameList);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("通过主键查询单条数据")
    @GetMapping("getGameById/{id}")
    public Result getGameById(@PathVariable long id) {
        GameQueryVO gameQueryVO = gameService.getGameById(id);
        return Result.ok(gameQueryVO);
    }

    /**
     * 新增数据
     *
     * @param gameCreatDTO 实体对象
     * @return 新增结果
     */
    @ApiOperation("添加游戏")
    @PostMapping("insertGame")
    public Result insertGame(@RequestBody @Valid GameCreatDTO gameCreatDTO) {
        gameService.insertGame(gameCreatDTO);
        return Result.ok();
    }

    /**
     * 修改数据
     *
     * @param gameEditDTO 实体对象
     * @return 修改结果
     */
    @ApiOperation("修改游戏")
    @PostMapping("updateGame")
    public Result updateGame(@RequestBody @Valid GameEditDTO gameEditDTO) {
        gameService.updateGame(gameEditDTO);
        return Result.ok();
    }

    /**
     * 通过id删除单条数据
     * @param id
     * @return
     */
    @DeleteMapping("deleteGameById/{id}")
    public Result deleteGameById(@PathVariable("id") long id) {
        gameService.removeGameById(id);
        return Result.ok();
    }



    /**
     * 批量删除游戏
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @ApiOperation("批量删除游戏")
    @DeleteMapping("removeBatch")
    public Result removeBatch(@RequestBody List<Long> idList) {
        gameService.removeByIds(idList);
        return Result.ok();
    }
}

